import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:manager/main.dart';
import 'package:manager/pages/home_page.dart';
import 'package:manager/pages/login_page.dart';
import 'package:manager/util/sp_util.dart';
import 'package:manager/util/user_util.dart';

class SplashPage extends StatefulWidget {
  @override
  SplashPageState createState() => new SplashPageState();
}

class SplashPageState extends State<SplashPage> {
  @override
  Widget build(BuildContext context) {
    return Container(
      //宽度
      width: double.infinity,
      //高度
      height: double.infinity,
      child: Image.asset('images/launch.png',
      fit: BoxFit.fill,),
    );
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    SpUtil.getInstance();
    Future.delayed(new Duration(seconds: 1), () {
      Navigator.pushAndRemoveUntil(context, new MaterialPageRoute(
        builder: (BuildContext context) {
          if (!UserUtil.isLogin()) {
            return LoginPage();
          } else {
            return HomePage();
          }
        },
      ), (route) => route == null);
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

  @override
  void didUpdateWidget(SplashPage oldWidget) {
    // TODO: implement didUpdateWidget
    super.didUpdateWidget(oldWidget);
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
  }
}
